package com.kyub.test.model;

import com.kyub.spring.gears.services.DaoService;

import java.util.List;
import java.util.ArrayList;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: sreghenzi
 * Date: 7-gen-2009
 * Time: 16.03.27
 * To change this template use File | Settings | File Templates.
 */
public class MockPersonDao implements DaoService {
    private ArrayList<Person> l = new ArrayList<Person>();

    public MockPersonDao() {
        MockPetDao mkp = new MockPetDao();
        for (int i = 0; i < 10; i++) {

            final Person person = new Person(Long.valueOf(i * 1L), "person " + i);
            person.getPets().addAll(mkp.list());
            l.add(person);

        }
    }

    public List list() {
        return l;
    }

    public Object load(Serializable id) {
        return l.get(Integer.parseInt(id.toString()));
    }

    public void save(Object command) {
        final Person person = (Person) command;
        if(person.getId() == null || person.getId() == 0){
            person.setId( Long.valueOf((long)(l.size())));

        }else{
          l.remove(person.getId());  
        }
         l.add(person);
    }

    public void delete(Object load) {
//To change body of implemented methods use File | Settings | File Templates.
    }
}
